package com.ch.engine.design.chain;

import java.util.Map;

/**
 * 验证请求参数的完整性和合法性的处理程序
 *
 * @author wangchunhui
 * @date 2023/7/20 10:04
 */
public class RequestValidationHandler implements Handler {
    private Handler nextHandler;

    @Override
    public void setNext(Handler handler) {
        this.nextHandler = handler;
    }

    @Override
    public void handleRequest(Request request) {
        if (areValidParameters(request.getParameters())) {
            if (nextHandler != null) {
                nextHandler.handleRequest(request);
            }
        } else {
            System.out.println("Invalid request parameters!");
        }
    }

    @Override
    public void handleResponse(Response response) {

    }

    private boolean areValidParameters(Map<String, String> parameters) {
        // 在此处进行请求参数验证逻辑
        // 假设所有参数都是合法的
        return true;
    }
}